//
//  LTComplainFeedBackVC.m
//  Learn
//
//  Created by zyl_macbookpro on 2024/4/1.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "LTComplainFeedBackVC.h"
#import "LTMineAPIManager.h"
@interface LTComplainFeedBackVC ()<UITableViewDelegate,UITableViewDataSource,YYTextViewDelegate>

@property(nonatomic ,strong)UITableView *tableView;

@property(nonatomic ,strong)UIView *tableHeaderView;

@property(nonatomic ,strong)UIView *tableFootorView;

@property(nonatomic ,strong)UILabel *numLabel;

@property(nonatomic ,strong)NSArray *titleArray;

/* 内容 **/
@property (nonatomic ,strong)YYTextView *contentTextView;

@end

@implementation LTComplainFeedBackVC
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self renderNavBarWithBackgroundImage:[UIImage imageWithColor:LTClearColor] backgroundColor:LTClearColor shadowColor:nil textAttributeDic:@{NSForegroundColorAttributeName:rgba(0, 0, 0, 1),NSFontAttributeName:MFontWithSize(17)} enableScrollEdgeAppearance:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"投诉";
    // Do any additional setup after loading the view.
    [self setBackButtonIsHidden:NO];
    [self.view addSubview:self.tableView];
   
}

- (void)tapClick
{
    [self.view endEditing:YES];
}
- (void)submitBtnAction
{
    [self tapClick];
    if (self.contentTextView.text.length == 0) {
        return;
    }
    [LTMineAPIManager addFeedbackWithParam:@{@"content":self.contentTextView.text} result:^(NSDictionary * _Nonnull dic) {
        [SVProgressHUD showSuccessWithStatus:@"投诉提交成功！"];
        [self.navigationController popViewControllerAnimated:YES];
    }];

}
- (void)textViewDidChange:(YYTextView *)textView
{
    if (textView.text.length > 500) {
        textView.text = [textView.text substringToIndex:498];
    }
    self.numLabel.text = [NSString stringWithFormat:@"%lu/500",(unsigned long)textView.text.length];
}
#pragma mark -UITableViewDelegate,UITableViewDelegate
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 0;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 0;
    
}


#pragma mark -getters and setters
-(UITableView *)tableView{
    if (!_tableView){
        _tableView =[[UITableView alloc] initWithFrame:CGRectMake(0, LTTopBarHeight + 16, LTScreenWidth, LTScreenHeight - LTTopBarHeight) style:UITableViewStylePlain];
        [_tableView setDelegate:self];
        [_tableView setDataSource:self];
        _tableView.bounces = NO;
        _tableView.backgroundColor = LTClearColor;
        [_tableView setTableFooterView:self.tableFootorView];
        [_tableView setTableHeaderView:self.tableHeaderView];
    }
    
    return _tableView;
}
-(UIView *)tableFootorView
{
    if (!_tableFootorView)
    {
        _tableFootorView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, LTScreenWidth, 146)];
        _tableFootorView.backgroundColor = LTClearColor;
        UIButton *submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        submitBtn.frame =CGRectMake(32, 32, LTScreenWidth - 64, 44);
       
        [submitBtn setTitle:@"提交" forState:UIControlStateNormal];
       // [_loginButton setTitleColor:rgba(181, 181, 181, 1) forState:UIControlStateNormal];
        [submitBtn setTitleColor:LTWhiteColor forState:UIControlStateNormal];
        [submitBtn.titleLabel setFont:MFontWithSize(14)];
        [submitBtn addTarget:self action:@selector(submitBtnAction) forControlEvents:UIControlEventTouchUpInside];
        submitBtn.backgroundColor = rgba(41, 121, 255, 1);
        submitBtn.layer.cornerRadius = 22;
        submitBtn.layer.shadowColor = rgba(41, 121, 255, 0.50).CGColor;
        submitBtn.layer.shadowOffset = CGSizeMake(0,4);
        submitBtn.layer.shadowOpacity = 1;
        submitBtn.layer.shadowRadius = 6;
        [_tableFootorView addSubview:submitBtn];
        [_tableFootorView setHeight:submitBtn.bottom + 10];
       
    }
    
    return _tableFootorView;
    
}

-(UIView *)tableHeaderView
{
    if (!_tableHeaderView)
    {
        _tableHeaderView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, LTScreenWidth, 250)];
        
        _tableHeaderView.backgroundColor = LTClearColor;
        UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(16, 10, LTScreenWidth - 32, 250)];
        contentView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
        contentView.layer.cornerRadius = 12;
        contentView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:50/255.0 blue:83/255.0 alpha:0.0500].CGColor;
        contentView.layer.shadowOffset = CGSizeMake(0,2);
        contentView.layer.shadowOpacity = 1;
        contentView.layer.shadowRadius = 12;
        
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(16, 20, contentView.width - 32, 210)];
      
        bgView.backgroundColor = rgba(247, 248, 250, 1);
        [bgView setAllCornersWithCornerRadius:12];
        
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(5,self.contentTextView.bottom,self.contentTextView.width,18);
        label.numberOfLines = 0;
        [bgView addSubview:label];
        label.textColor = rgba(209, 210, 213, 1);
        label.font = RFontWithSize(13);
        label.text = @"0/500";
        label.textAlignment = NSTextAlignmentRight;
        self.numLabel = label;
        [bgView addSubview:self.contentTextView];
        [contentView addSubview:bgView];
        [_tableHeaderView addSubview:contentView];
        
    }
    
    return _tableHeaderView;
    
}
-(YYTextView *)contentTextView
{
    if (!_contentTextView) {
        _contentTextView = [[YYTextView alloc] initWithFrame:CGRectMake(12, 12, LTScreenWidth - 64 - 24, 180)];
        _contentTextView.font = RFontWithSize(13);
        _contentTextView.textAlignment = NSTextAlignmentJustified;
        _contentTextView.placeholderText = @"补充描述和说明有助于我们为您提供更好的服务～";
        _contentTextView.placeholderTextColor = rgba(209, 210, 213, 1);
        _contentTextView.delegate = self;
        _contentTextView.textColor = LTTextBlack;
      
    }
    return _contentTextView;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
